import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
export const columns: BasicColumn[] = [
  {
    title: '应用标识',
    dataIndex: 'clientId',
    width: 120,
  },
  {
    title: '应用名称',
    dataIndex: 'clientName',
    width: 100,
  },
  {
    title: '回调地址',
    dataIndex: 'webServerRedirectUri',
    width: 120,
  },
  {
    title: 'oauth授权方式',
    dataIndex: 'authorizedGrantTypes',
    width: 120,
  },
  {
    title: '自动审批',
    dataIndex: 'autoapprove',
    width: 60,
    customRender: ({ text }) => {
      const color = text == 'true' ? 'green' : 'gray';
      const value = text == 'true' ? '是' : '否';
      return render.renderTag(value, color);
      //return render.renderTag(render.renderDict(text, 'notify_send_status'), color);
    },
  },
  {
    title: '令牌时效(s)',
    dataIndex: 'accessTokenValiditySeconds',
    width: 60,
  },
  {
    title: '刷新失效(s)',
    dataIndex: 'refreshTokenValiditySeconds',
    width: 60,
  },
  {
    title: '令牌类型',
    dataIndex: 'tokenFormat',
    width: 100,
    customRender: ({ text }) => {
      const value = text == 'reference' ? '引用令牌' : '自包含令牌';
      return value;
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '应用标识',
    field: 'clientId',
    component: 'JInput',
    colProps: { span: 6 },
  },
  {
    label: '应用名称',
    field: 'clientName',
    component: 'JInput',
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '应用标识',
    field: 'clientId',
    required: true,
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
  },
  {
    label: '应用名称',
    field: 'clientName',
    required: true,
    component: 'Input',
  },
  {
    field: 'clientSecretStr',
    component: 'InputGroup',
    label: '应用密钥',
    required: true,
    slot: 'csecret',
  },
  {
    label: '回调地址',
    field: 'webServerRedirectUri',
    component: 'Input',
  },
  {
    label: '自动审批',
    field: 'autoapprove',
    component: 'Switch',
    helpMessage: ['在使用统一认证服务生效', '是:表示登录成功后不跳转到授权页面', '否:表示登录成功后跳转到授权页面'],
    defaultValue: 'true',
    componentProps: {
      checkedValue: 'true',
      checkedChildren: '是',
      unCheckedValue: 'false',
      unCheckedChildren: '否',
    },
  },
  {
    label: '授权模式',
    field: 'authorizedGrantTypes',
    required: true,
    component: 'JCheckbox',
    helpMessage: ['OAUTH2授权模式'],
    defaultValue: 'authorization_code,password,client_credentials,implicit,refresh_token,password_code',
    componentProps: {
      options: [
        { label: '授权码模式', value: 'authorization_code' },
        { label: '密码模式', value: 'password' },
        { label: '客户端模式', value: 'client_credentials' },
        { label: '简化模式', value: 'implicit' },
        { label: '刷新Token', value: 'refresh_token' },
        { label: '密码验证码模式', value: 'password_code' },
        { label: 'openId模式', value: 'openId' },
        { label: '手机密码模式', value: 'mobile_password' },
        { label: '短信验证码模式', value: 'sms_code' },
        { label: '用户代理模式', value: 'user_agent' },
        { label: 'CAS模式', value: 'cas_ticket' },
        { label: '设备模式', value: 'urn:ietf:params:oauth:grant-type:device_code' },
      ],
    },
  },
  {
    label: '授权范围',
    field: 'scope',
    required: true,
    component: 'JCheckbox',
    helpMessage: ['OAUTH2统一认证授权范围'],
    defaultValue: 'all',
    componentProps: {
      options: [
        { label: '所有', value: 'all' },
        { label: '个人信息', value: 'profile' },
        { label: '读取消息', value: 'message.read' },
        { label: '添加新消息', value: 'message.write' },
        { label: '范围示例', value: 'other.scope' },
      ],
    },
  },
  {
    label: '令牌时效',
    field: 'accessTokenValiditySeconds',
    required: true,
    component: 'InputNumber',
    defaultValue: 3600,
    rules: [{ required: true, pattern: /^\d+$/, message: '请输入正确的ID时效' }],
    componentProps: {
      //带标签的 input，设置后置标签
      addonAfter: '秒',
    },
  },
  {
    label: '刷新时效',
    field: 'refreshTokenValiditySeconds',
    required: true,
    component: 'InputNumber',
    defaultValue: 28800,
    rules: [{ required: true, pattern: /^\d+$/, message: '请输入正确的ID时效' }],
    componentProps: {
      //带标签的 input，设置后置标签
      addonAfter: '秒',
    },
  },
  {
    label: '令牌类型',
    field: 'tokenFormat',
    required: true,
    component: 'RadioGroup',
    defaultValue: 'reference',
    componentProps: {
      options: [
        { label: '引用令牌(不透明)', value: 'reference' },
        { label: '自包含令牌(jwt)', value: 'self-contained' },
      ],
    },
  },
];
